/*
	Copyright (c) 2007, ANYwebcam.com Pty Ltd. All rights reserved.

	The software in this package is published under the terms of the BSD style 
	license, a copy of which has been included with this distribution in the 
	license.txt file.
*/
package com.anywebcam.di.component
{
	import com.anywebcam.di.*;
	import com.anywebcam.di.component.*;

	import flexunit.framework.TestCase;
	import flexunit.framework.TestSuite;

	public class DecoratingComponentTest extends TestCase
	{
		public static function suite():TestSuite
		{
			var ts:TestSuite = new TestSuite();

			var tests:Array = 
			[
				'shouldPassAllDIComponentPropertyAndMethodCallsToDIComponentBeingDecorated',
			];

			tests.forEach( function( methodName:String, index:int, array:Array ):void
			{
				ts.addTest( new DecoratingComponentTest( methodName ) );
			});

			return ts;
		}

		public function DecoratingComponentTest( method:String )
		{
			super( method );
		}
		
		public function shouldPassAllDIComponentPropertyAndMethodCallsToDIComponentBeingDecorated():void
		{
			var decoratedComponent:DecoratedComponent = new DecoratedComponent();
			var component:DecoratingComponent = new DecoratingComponent( decoratedComponent );
			
			assertEquals( 'Expecting DecoratingComponent::key to return the key of the decorated component', decoratedComponent.key, component.key );
			assertEquals( 'Expecting DecoratingComponent::type to return the type of the decorated component', decoratedComponent.type, component.type );
			assertStrictlyEquals( 'Expecting DecoratingComponent::getInstance to return the same as the decorated component', decoratedComponent.getInstance( null ), component.getInstance( null ) );
		}
	}
}

import com.anywebcam.di.*;
import com.anywebcam.di.component.*;
import com.anywebcam.reflection.*;

internal class DecoratedComponent implements DIComponent
{
	public function DecoratedComponent()
	{
	}
	
	public function get key():Object
	{
		return DecoratedComponent;
	}
	
	public function get type():Class
	{
		return DecoratedComponent;
	}
	
	public function get classInfo():ClassInfo
	{
		return new ClassInfo( DecoratedComponent );
	}
	
	public function getInstance( container:DIContainer ):Object
	{
		return this;
	}
}